import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';

export enum MessageType {
  USER_TO_DOCTOR = 'user_to_doctor',
  DOCTOR_TO_USER = 'doctor_to_user',
  TOPIC_COLLECTED = 'topic_collected',
  DOCTOR_VERIFIED = 'doctor_verified',
}

@Entity()
export class Message {
  @ApiProperty({ description: '消息唯一标识', example: 1 })
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({ description: '发送者 ID', example: 1 })
  @Column()
  sender_id: number;

  @ApiProperty({ description: '接收者 ID', example: 2 })
  @Column()
  receiver_id: number;

  @ApiProperty({ description: '消息内容', example: '你好' })
  @Column({ type: 'text' })
  content: string;

  @ApiProperty({
    description: '消息类型',
    enum: MessageType,
    example: MessageType.USER_TO_DOCTOR,
  })
  @Column({ type: 'enum', enum: MessageType })
  message_type: MessageType;

  @ApiProperty({ description: '消息发送时间', example: '2025-05-09 19:51:00' })
  @Column({ type: 'datetime' })
  send_time: Date;

  @ApiProperty({ description: '消息是否已读', example: false })
  @Column({ type: 'boolean', default: false })
  is_read: boolean;

  @ApiProperty({
    description: '额外信息，如话题 ID 等',
    example: '{"topicId": 10}',
    nullable: true,
  })
  @Column({ type: 'text', nullable: true })
  extra_data: string;
}
